﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using LTSMZ.life.Model;
using LTSMZ.life.BLL;
using System.Data;
using Webdiyer.WebControls.Mvc;
namespace LTSMZ.life.Admin.Controllers
{
    public class HomeController : Controller
    {
        //
        // GET: /Home/
        public ActionResult login()
        {
            return View();
        }
        public ActionResult Index()
        {
            return View();
        }
        /// <summary>
        /// 第二类别下拉框
        /// </summary>
        /// <returns></returns>
        public ActionResult goods_add()
        {
            ProductBll bll = new ProductBll();
            ViewBag.Sid = new SelectList(bll.ShowSecondType(), "Sid", "Sname");
            return View();
        }


        /// <summary>
        /// 商品显示
        /// </summary>
        /// <returns></returns>
        public ActionResult goods_Show(int pageIndex=1)
        {
            int pageSize = 10;
            ProductBll bll = new ProductBll();
            PagedList<Product> list = new PagedList<Product>(bll.show(), pageIndex, pageSize);
            return View(list);
        }
        /// <summary>
        /// 商品添加
        /// </summary>
        /// <param name="p"></param>
        /// <returns></returns>
        public ActionResult Addgoods(Product p)
        {
            ProductBll bll = new ProductBll();
            if (bll.ProductAdd(p) > 0)
            {
                return Content("<script>alert('添加成功!');location.href='/Home/goods_Show'</script>");
            }
            else
            {
                return Content("<script>alert('添加失败!');location.href='/Home/goods_add'</script>");
            }
        }
        public ActionResult FirstypeShow()
        {
            return View();
        }
        /// <summary>
        /// 一级类别的显示
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <returns></returns>
        public ActionResult FirsType_Show( int pageIndex=1)
        {
            int pageSize=2;
            FirstTypeBll bll = new FirstTypeBll();
            PagedList<FirstType> list = new PagedList<FirstType>(bll.FirstTypeShow(), pageIndex, pageSize);
            return View(list);
        }
        /// <summary>
        /// 一级类别添加页面
        /// </summary>
        /// <returns></returns>
        public ActionResult AddFirstype()
        {
            return View();
        }
        /// <summary>
        /// 二级类别的显示
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public ActionResult SecondTypeShow(int id, int pageIndex=1)
        {
            int pageSize = 10;
            Session["id"] = id;
            SecondTypeBll bll=new SecondTypeBll();
            PagedList<SecondType> list = new PagedList<SecondType>(bll.SecondTypeShow(id), pageIndex, pageSize);
            return View(list);
        }
        /// <summary>
        /// 二级类别的删除
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public ActionResult DelSecondType(int id)
        {
            SecondTypeBll bll=new SecondTypeBll();
            if(bll.DelSecondType(id)>0)
            {
                return Content("<script>alert('删除成功');location.href='/Home/FirsType_Show'</script>");
            }
            else
            {
                return Content("<script>alert('删除成功');location.href='/Home/FirsType_Show'</script>");
            }
        }
        /// <summary>
        /// 二级类别的添加界面
        /// </summary>
        /// <returns></returns>
        public ActionResult AddSecond()
        {
            int Fid = Convert.ToInt32( Session["id"]);
            ViewBag.Fid = Fid;
            return View();
        }
        /// <summary>
        /// 二级类别的添加
        /// </summary>
        /// <returns></returns>
        public ActionResult AddSecond_Add()
        {
            SecondTypeBll bll = new SecondTypeBll();
            SecondType s = new SecondType();
            s.Sname = Request["name"].ToString();
            s.Fid = Convert.ToInt32(Request["id"]);
            if(bll.AddSecondType(s)>0)
            {
                return Content("1");
            }
            else
            {
                return Content("0");
            }
        }
        /// <summary>
        /// 显示订单
        /// </summary>
        /// <returns></returns>
        public ActionResult ShowOrders()
        {
            OrdersBll bll = new OrdersBll();
            List<OrdersComment> li = bll.Ordersshow();
            return View(li);
        }
        /// <summary>
        /// 修改状态二（融合版）
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public ActionResult AlterProduct1(int id)
        {
            ProductBll bll=new ProductBll();
            if(bll.AlterProduct1(id)>0)
            {
                return Content("<script>alert('操作成功');location.href='/Home/goods_Show'</script>");
            }
            else
            {
                return Content("<script>alert('系统繁忙，请重新操作');location.href='/Home/goods_Show'</script>");
            }
        }


        /// <summary>
        /// 会员业务
        /// </summary>
        /// <returns>会员显示</returns>
        public ActionResult showmember()
        {

            return View();
        }
        /// <summary>
        /// 显示商品下拉框
        /// </summary>
        /// <returns></returns>
        public ActionResult ShowPid()
        {
            //StockBll sbll=new StockBll();
            //ViewBag.Pid = new SelectList(sbll.Selectpstorck(),"Pid","Pname");
            StockBll sbll = new StockBll();
            List<Product> list = sbll.Selectpstorck();
            //添加测试数据
            //List<Product> list = new List<Product>();
            //Product p = new Product();
            //p.Pid = 1;
            //p.Pname = "张三";
            //list.Add(p);
            return Json(list, JsonRequestBehavior.AllowGet);
        }

        /// <summary>
        /// 库存添加
        /// </summary>
        /// <returns></returns>
        public ActionResult AddStock()
        {

            return View();
        }
        /// <summary>
        /// 添加库存方法
        /// </summary>
        /// <returns></returns>
        public ActionResult AddSto()
        {
            StockBll sbll = new StockBll();
            Stock s = new Stock();
            s.SpotStocks = int.Parse(Request["SpotStocks"]);
            s.AvailableStocks = int.Parse(Request["AvailableStocks"]);
            s.StockState = int.Parse(Request["StockState"]);
            s.Sum = int.Parse(Request["Sum"]);
            s.Pid = int.Parse(Request["Pid"]);
            //s.Pid = int.Parse(Request["Pid"]);
            if (sbll.AddStock(s) > 0)
            {
                return Content("1");
            }
            else
            {
                return Content("0");
            }
        }

        /// <summary>
        /// 库存界面
        /// </summary>
        /// <returns></returns>
        public ActionResult KucunShow()
        {
            return View();
        }
        /// <summary>
        /// 获取订单信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        //public ActionResult GetOrderId(int id)
        //{
        //    OrdersBll bll=new OrdersBll();
        //    Orders o = bll.GetOrderId(id);
        //    return View(o);
        //}
        /// <summary>
        /// 第一类别的添加
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public ActionResult Add_FirsType(string name)
        {
            FirstTypeBll bll=new FirstTypeBll();
            if(bll.Add_FirsType(name)>0)
            {
                return Content("1");
            }
            else
            {
                return Content("0");
            }
        }
        /// <summary>
        /// 一级类别的删除
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public ActionResult Del_FirsType(int id)
        {
            FirstTypeBll bll = new FirstTypeBll();
            if(bll.Del_FirsType(id)>0)
            {
                return Content("<script>alert('删除成功');location.href='/Home/Firstype_Show'</script>");
            }
            else
            {
                return Content("<script>alert('删除失败');location.href='/Home/Firstype_Show'</script>");
            }
        }
        /// <summary>
        /// 根据编号获取第一类别的信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public ActionResult UptFirstype(int id)
        {
            FirstTypeBll bll = new FirstTypeBll();
            FirstType f = bll.Get_FirsType(id);
            return View(f);
        }
        /// <summary>
        /// 第一类别的修改
        /// </summary>
        /// <param name="f"></param>
        /// <returns></returns>
        public ActionResult Upt_FirsType(FirstType f)
        {
            FirstTypeBll bll = new FirstTypeBll();
            if (bll.Upt_FitsType(f) > 0)
            {
                return Content("<script>alert('修改成功');location.href='/Home/Firstype_Show'</script>");
            }
            else
            {
                return Content("<script>alert('修改失败');location.href='/Home/Firstype_Show'</script>");
            }
        }
        /// <summary>
        /// 进货
        /// </summary>
        /// <param name="Jin"></param>
        /// <param name="id"></param>
        /// <returns></returns>
        public ActionResult Jin_Stock(int Jin,int id)
        {
            StockBll bll = new StockBll();
            if(bll.JinStock(Jin,id)>0)
            {
                return Content("1");
            }
            else
            {
                return Content("0");
            }
        }
        /// <summary>
        /// 根据编号获取库存信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public ActionResult Get_Stock(int id)
        {
            StockBll bll=new StockBll();
            ViewBag.id = id;
            Stock s = bll.Get_Stock(id);
            return View(s);
        }
        /// <summary>
        /// 库存显示
        /// </summary>
        /// <returns></returns>
        public ActionResult ShowSctok()
        {
            StockBll bll = new StockBll();
            List<Stock>list = bll.StockShow();
            return Json(list, JsonRequestBehavior.AllowGet);
        }
    }
}